<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0"
                xmlns:xhtml="http://www.w3.org/1999/xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xhtml xsl xs">

  <xsl:output method="xml"
              indent="yes"
              encoding="iso-8859-1"
              doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
              doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  />

  <xsl:template match="/">
    <html xmlns:xhtml="http://www.w3.org/1999/xhtml">
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <head>
        <title>
          <xsl:call-template name="title" />
        </title>
        <style>
          body{
          color:#505050;
          font-family: Arial, Helvetica, sans-serif;
          font-size:8pt;
          font-weight:normal;
          letter-spacing:normal;
          line-height:15pt;
          }
          .errors{
          color:#000000;
          font-family: Arial, Helvetica, sans-serif;
          font-size:7pt;
          padding-left:10px;
          font-weight:normal;
          letter-spacing:normal;
          line-height:9pt;
          padding-top:9px;
          padding-bottom:6px;
          text-transform:uppercase
          }
          a{
          color:#505050;
          font-family: Arial, Helvetica, sans-serif;
          font-size:8pt;
          font-weight:normal;
          letter-spacing:normal;
          line-height:13pt;
          text-decoration:underline;
          }
          a:hover{
          color: #f78f15;
          font-family: Arial, Helvetica, sans-serif;
          font-size:8pt;
          font-weight:normal;
          letter-spacing:normal;
          line-height:13pt;
          text-decoration:underline;
          }
          .footer{
          border-top:1px solid #e3e3e3;
          padding-top:3px;
          font-size: 11px;
          margin-top:10px
          }
          .logo{
          padding-bottom:3px;
          font-size: 11px;
          }
          .title{
          text-align:right;
          font-size:21px;
          color:#f78f15
          }
          .toptable{
          background:#000000;
          color:#FFFFFF;
          text-transform:uppercase;
          font-size:12px;
          font-weight:bold;
          padding:2px 5px 2px 10px
          }
          img {
          border:none
          }
          .tableborder{
          border-bottom: 1px solid #e3e3e3;
          }
          table.tableborder td{
          padding:3px 0px 3px 10px
          }
          .spacer{
          height:13px;
          }
        </style>
      </head>
      <body topmargin="0">
        <table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td colspan="2" class="spacer" />
          </tr>
          <tr>
            <td width="120" class="logo">
              <img height="37" width="115" alt="Orbit One" src="https://elmah.orbitone.com/img/logo.gif"
                  style="width: 115px; height: 37px;" />
            </td>
            <td width="436" class="title">
              <xsl:call-template name="title" />
            </td>
          </tr>
          <tr>
            <td colspan="2" class="spacer" />
          </tr>
        </table>

        <xsl:call-template name="report" />

        <table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="spacer"></td>
          </tr>
          <tr>
            <td style="height:20px;font-family: Arial, Helvetica, sans-serif;font-size:7pt;font-weigth:normal;letter-spancing:normal;">
              &#169;Orbit One 2007 - Raas Van Gaverestraat 83, B-9000 Gent - tel. +32 (0)9 265 74 20 - Comments to <a href="mailto:info@orbitone.com">info@orbitone.com</a> - Privacy State
            </td>
          </tr>
        </table>
      </body>
    </html>
  </xsl:template>

  <!-- title template -->
  <xsl:template name="title">
    <xsl:choose>
      <xsl:when test="//report//@name = 'daily'">
        <xsl:text>Daily report </xsl:text>
        <xsl:value-of select="//report//@from"/>
        <xsl:text> - </xsl:text>
        <xsl:value-of select="//report//@to"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>Alert report </xsl:text>
        <xsl:value-of select="//report//@application"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- errorLevel template -->
  <xsl:template name="errorLevel">
    <xsl:choose>
      <xsl:when test="@level = '0' or @level = '1'">
        <img src="https://elmah.orbitone.com/img/icon_errorLevel1.gif" />
      </xsl:when>
      <xsl:when test="@level = '2' or @level = '3'">
        <img src="https://elmah.orbitone.com/img/icon_errorLevel2.gif" />
      </xsl:when>
      <xsl:otherwise>
        <img src="https://elmah.orbitone.com/img/icon_errorLevel3.gif" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- errorType template -->
  <xsl:template name="errorType">
    <xsl:choose>
      <xsl:when test="@type = 'Code'">
        <img src="https://elmah.orbitone.com/img/icon_code.gif" />
      </xsl:when>
      <xsl:otherwise>
        <img src="https://elmah.orbitone.com/img/icon_infrastructure.gif" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- topApplications template -->
  <xsl:template name="topApplications">
    <table width="200" border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="4" class="toptable">
          top applications
        </td>
      </tr>
      <tr>
        <td colspan="4">
          errors from <xsl:value-of select ="//report//@from"/>
        </td>
      </tr>
      <xsl:for-each select="//report//applications//application">
        <tr>

          <td style="width: 170px">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="@link" />
              </xsl:attribute>
              <xsl:value-of select="@name"/>
            </a>
          </td>
          <td style="width: 30px">
            <xsl:value-of select="@count"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>
  
  <!-- messages template -->
  <xsl:template name="messages">
    
    <xsl:variable name="tableSize">
      <xsl:if test="//report//@name = 'daily'">
        <xsl:value-of select="445" />
      </xsl:if>
      <xsl:if test="//report//@name = 'alert'">
        <xsl:value-of select="645" />
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="colSize">
      <xsl:if test="//report//@name = 'daily'">
        <xsl:value-of select="300" />
      </xsl:if>
      <xsl:if test="//report//@name = 'alert'">
        <xsl:value-of select="500" />
      </xsl:if>
    </xsl:variable>

    <table width="{$tableSize}" border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="4" class="toptable">
          Error message
        </td>
      </tr>
      <xsl:for-each select="//report//messages//message">
        <tr>
          <td style="width: {$colSize}">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="@link" />
              </xsl:attribute>
              <xsl:value-of select="@name"/>
            </a>
          </td>
          <td style="width: 59px" align="center">
            <xsl:call-template name="errorType" />
          </td>
          <td style="width: 59px" align="center">
            <xsl:call-template name="errorLevel" />
          </td>
          <td style="width: 25px" align="left">
            <xsl:value-of select="@count"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>

  <!-- urls template -->
  <xsl:template name="urls">
    <table width="450" border="0" align="left" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="4" class="toptable">
          Url Errors
        </td>
      </tr>
      <xsl:for-each select="//report//urls//url">
        <tr>
          <td style="width: 425px">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="@link" />
              </xsl:attribute>
              <xsl:value-of select="@name"/>
            </a>
          </td>
          <td style="width: 25px" colspan="3" align="left">
            <xsl:value-of select="@count"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>

  <!-- report template -->
  <xsl:template name="report">
    <xsl:choose>
      <xsl:when test="//report//@name = 'daily'">
        <table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td>
              <xsl:call-template name="messages" />
            </td>
            <td width="5px" rowspan="3" />
            <td width="200px" rowspan="3" valign="top">
              <xsl:call-template name="topApplications" />
            </td>
          </tr>
          <tr>
            <td class="spacer" />
          </tr>
          <tr>
            <td>
              <xsl:call-template name="urls" />
            </td>
          </tr>
        </table>
      </xsl:when>
      <xsl:otherwise>
        <table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width = "100px" rowspan ="1" />
            <td valign="top" style="padding-right:10px">
              <xsl:call-template name="messages" />
            </td>
            <td width = "100px" rowspan ="1" />
          </tr>
        </table>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>